import time
import cv2
import uiautomation as auto
from zz import zz_code, zz_str, zz_img
from game import zz_game
import cv2


def capture():
    # 截图保存
    auto.uiautomation.SetGlobalSearchTimeout(3)  # 设置全局搜索超时 5

    window = auto.PaneControl(searchDepth=1, ClassName='地下城与勇士')  # search 2 times
    # window.SetTopmost(False)
    window.Click(900, 84)

    img_path = zz_game.get_pc_temp_file()
    window.CaptureToImage(img_path)
    return img_path


def main():
    img_src = './test.png'
    img_src = ''
    if zz_str.is_null_or_empty(img_src):
        img_src = capture()

    img_arr = cv2.imread(img_src)
    cv2.imshow("preview", img_arr)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


if __name__ == '__main__':
    main()
